package com.study.d1_servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/request")
public class RequestServelt extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、获取请求方式
        String method = req.getMethod();
        System.out.println("请求方式："+method);
        //2、获取请求路径
        String requestURI = req.getRequestURI();
        System.out.println("URI:"+requestURI);
        StringBuffer requestURL = req.getRequestURL();
        System.out.println("URL:"+requestURL);
        //3、获取协议
        String scheme = req.getScheme();
        System.out.println("scheme:"+scheme);
        //4、获取请求头（host）
        String host = req.getHeader("Host");
        System.out.println("host:"+host);
        //5、获取请求参数
        String name = req.getParameter("name");
        System.out.println("name:"+name);
        //6、获得所有查询参数
        String queryString = req.getQueryString();
        System.out.println("queryString:"+queryString);
    }
}
